package com.tom;

import java.sql.*;

public class MyConnection {
	Connection conn;
	Statement stmt;
	PreparedStatement pstmt;
	String driverStr="";
	String urlStr="";
	String user="";
	String password="";
	
	public MyConnection (){
		this("");
	}
	
	public MyConnection (String DB){
		
		switch (DB.toUpperCase()) {
		case "MSSQL" : 
			driverStr="com.microsoft.sqlserver.jdbc.SQLServerDriver";
			urlStr="jdbc:sqlserver://127.0.0.1:1433;database=CH06範例資料庫";
			user="sa";
			password="111";
			break;
		case "MYSQL" : 
			driverStr="com.mysql.jdbc.Driver";
			urlStr="jdbc:mysql://j.snpy.org:3306/j102u05";
			user="j102u05";
			password="j102u05.989";
			break;
		case "ORACLE" : 
			driverStr="oracle.jdbc.OracleDriver";
			urlStr="jdbc:oracle:thin:@myhost:1521:orcl;user=scott;password=tiger";
			break;
		}
		try {
			Class.forName(driverStr);
			conn=DriverManager.getConnection(urlStr, user, password);
			stmt=conn.createStatement();			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}		
	}	

	public Connection getMyConn(){
	   return conn;	
	}
	
	public Statement getMyStatement(){
	   return stmt;
	}

	public PreparedStatement getPstmt() {
		return pstmt;
	}

	public void setPstmt(PreparedStatement pstmt) {
		this.pstmt = pstmt;
	}
	
}